package com.ch.forum.controller;

import com.ch.forum.bo.ReplyVo;
import com.ch.forum.bo.ResponseResult;
import com.ch.forum.model.ReplyModel;
import com.ch.forum.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/reply")
@Controller
public class ReplyController {

    @Autowired
    private ReplyService replyService;

    public static final String ADD_PAGE = "reply/add";

    @GetMapping(value = "add")
    public String add(){
        return ADD_PAGE;
    }

    @PostMapping()
    @ResponseBody
    public ResponseResult addReply(ReplyVo data){
        return replyService.addReply(data);
    }

    @GetMapping("/{id}/{pageNo}/{pageSize}")
    @ResponseBody
    public ResponseResult page(@PathVariable("id")Long id,
                               @PathVariable("pageNo")int pageNo,
                               @PathVariable("pageSize")int pageSize){
        return replyService.findReplyPageByArtId(id, pageNo, pageSize);
    }

    @GetMapping("/my/{userId}")
    @ResponseBody
    public ResponseResult findMyReplyByUserId(@PathVariable("userId")Long userId,
                               @RequestParam("pageNo")int pageNo,
                               @RequestParam("pageSize")int pageSize){
        return replyService.findMyReplyByUserId(userId, pageNo, pageSize);
    }

}
